export const jsonp = app => {
  app.use(async(ctx, next) => {
    const callback = ctx.query.callback
    if (callback) {
      ctx.body = `;typeof ${callback} === "function" && ${callback}(${JSON.stringify(ctx.body)});`
    }
    ctx.set({
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Headers': 'X-Requested-With',
      'Access-Control-Allow-Methods': 'POST,GET,DELETE,OPTIONS',
      'X-Powered-By': '1.0.0',
      'Content-Type': 'application/x-javascript; Charset=utf-8'
    })
    await next()
  })
}
